﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Data.Objects;
using Data.Configuration;
using System.Data.SqlClient;

namespace Data
{
    public class DataContext
    {
        public static Model BuildContext()
        {
            String connection = @"Data Source=HIGOR-PC\SQLEXPRESS;Initial Catalog=OneToOne;Integrated Security=SSPI;";
            var builder = new ContextBuilder<Model>();

            //Adicionamos todas as configurações
            builder.Configurations.Add(new PersonConfiguration());
            builder.Configurations.Add(new BankAccountConfiguration());


            var ctx = builder.Create(new SqlConnection(connection));
            ctx.ContextOptions.LazyLoadingEnabled = true;
            return builder.Create(new SqlConnection(connection));

        }

        public static void CreateDataBase()
        {
            var ctx = BuildContext();
            if (ctx.DatabaseExists())
               ctx.DeleteDatabase();
            
            ctx.CreateDatabase();
        }


    }
}
